package org.soderiakelvy.controller.util;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class UtilDate {
	

		/**
		 * Devuelve el nombre del dia segun la fecha enviada por parametro
		 * @param fecha en formato Date
		 * @return una string con el nombre del dia de la semana.
		 */
		public static String getNombreDelDia(Date fecha){
			Calendar cal = new GregorianCalendar();
			String dia = "";
			cal.setTime(fecha);
			int numeroDeDia = cal.get(Calendar.DAY_OF_WEEK);
			
			switch (numeroDeDia) {
			case 1:
				dia = "Domingo";
				break;
			case 2: 
				dia = "Lunes";
				break;
			case 3: 
				dia = "Martes";
				break;
			case 4: 
				dia = "Miercoles";
				break;
			case 5: 
				dia = "Jueves";
				break;
			case 6: 
				dia = "Viernes";
				break;
			case 7: 
				dia = "Sabado";
				break;
			default:
				break;
			}
			
			return dia;
		}
	
	
	  public static Date getPrimerDiaDelMes(Date date) {
	    	 Calendar cal = new GregorianCalendar();
	    	 cal.setTime(date);		         
	         cal.set(cal.get(Calendar.YEAR),
	                 cal.get(Calendar.MONTH),
	                 cal.getActualMinimum(Calendar.DAY_OF_MONTH),
	                 cal.getMinimum(Calendar.HOUR_OF_DAY),
	                 cal.getMinimum(Calendar.MINUTE),
	                 cal.getMinimum(Calendar.SECOND));
	         return cal.getTime();
	     }
	
	     public static Date getPrimerDiaDelProximoMes(Date date) {
	    	 Calendar cal = new GregorianCalendar();
	    	 cal.setTime(date);
	    	 cal.add(Calendar.MONTH, 1);
	    	 cal.set(cal.get(Calendar.YEAR),
	                 cal.get(Calendar.MONTH),
	                 cal.getActualMinimum(Calendar.DAY_OF_MONTH),
	                 cal.getMinimum(Calendar.HOUR_OF_DAY),
	                 cal.getMinimum(Calendar.MINUTE),
	                 cal.getMinimum(Calendar.SECOND));
	         return cal.getTime();
	     }
	
	 
	     public static Date getUltimoDiaDelMes(Date date) {
	    	 Calendar cal = new GregorianCalendar();
	    	 cal.setTime(date);
	         cal.set(cal.get(Calendar.YEAR),
	                 cal.get(Calendar.MONTH),
	                 cal.getActualMaximum(Calendar.DAY_OF_MONTH),
	                 cal.getMaximum(Calendar.HOUR_OF_DAY),
	                 cal.getMaximum(Calendar.MINUTE),
	                 cal.getMaximum(Calendar.SECOND));
	         return cal.getTime();
	     }
}
